package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.util.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类品牌中间表 前端控制器
 *
 * @author lhw
 * @since 2022-12-25
 */
@Api(tags = "分类品牌中间表控制器")
@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    @GetMapping("/findTrademarkList/{category3Id}")
    @ApiOperation("根据分类id查询品牌列表")
    public Result<List<BaseTrademark>> findTrademarkList(@PathVariable("category3Id")Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.findTrademarkList(category3Id);
        return Result.ok(list);
    }

    @ApiOperation("根据分类id获取可选的品牌列表")
    @GetMapping("/findCurrentTrademarkList/{category3Id}")
    public Result<List<BaseTrademark>> findCurrentTrademarkList(@PathVariable("category3Id")Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(list);
    }

    @ApiOperation("保存分类品牌关联")
    @PostMapping("/save")
    public Result saveBaseCategoryTrademark(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.saveBaseCategoryTrademark(categoryTrademarkVo);
        return Result.ok();
    }

    @ApiOperation("删除分类品牌关联")
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result removeCategoryTrademark(@PathVariable("category3Id")Long category3Id,@PathVariable("trademarkId")Long trademarkId){
        baseCategoryTrademarkService.removeCategoryTrademark(category3Id,trademarkId);
        return Result.ok();
    }

}
